import { Message } from 'element-ui'
import { api } from 'igw-library/lib/sdk'
import { getToken } from '@/utils/auth'
export function sdkRequest(requestMethod, requestUrl, params, page) {
	const obj = {
		data: {
			body: params || {},
			page: page || {}
		},
		code: 0,
		msg: 'ok',
		serialNo: '',
		success: true
	}
	return new Promise((resolve, reject) => {
		api.request({
			method: requestMethod,
			url: requestUrl,
			data: obj,
			headers: {
				'Content-Type': 'application/json',
				'X-Token': getToken()
			},
			widthCredentials: true,
			timeout: 600000
		}).then(res => {
			const data = JSON.parse(res.response)
			data.msgDesc = data.msg
			if (data.code === 0) {
				data.msgCode = 'Y'
				resolve(data)
			} else {
				Message({ message: data.msg, customClass: 'el-messageClass', type: 'error' })
				resolve(data)
			}
		}).catch(err => {
			reject(err)
			Message({ message: err, customClass: 'el-messageClass', type: 'error' })
		})
	})
}
